var mobi=isMobile();
if(mobi){
    sessionStorage.removeItem('current_index');
}
    $('.sidebar-elements li.parent').click(function () {
        //获取当前点击的是哪一个li标签,其实就是获取它的下标
        var index = $('.sidebar-elements li.parent').index(this);
        //将下标值存入session中
        if(!mobi){
            sessionStorage.setItem('current_index',index);
        }
    });
//在点击事件之外,获取session中的下标值,然后给对应的li标签加上open属性
    var current_index = sessionStorage.getItem('current_index');

    $('.sidebar-elements li.parent').eq(current_index).addClass('open');






function isMobile() {
    var userAgentInfo = navigator.userAgent;

    var mobileAgents = [ "Android", "iPhone", "SymbianOS", "Windows Phone", "iPad","iPod"];

    var mobile_flag = false;

    //根据userAgent判断是否是手机
    for (var v = 0; v < mobileAgents.length; v++) {
        if (userAgentInfo.indexOf(mobileAgents[v]) > 0) {
            mobile_flag = true;
            break;
        }
    }

    var screen_width = window.screen.width;
    var screen_height = window.screen.height;

    //根据屏幕分辨率判断是否是手机
    if(screen_width < 500 && screen_height < 800){
        mobile_flag = true;
    }

    return mobile_flag;
}